//
//  CellOfVideo.m
//  RunningMan
//
//  Created by dllo on 16/5/19.
//  Copyright © 2016年 JohnnyB. All rights reserved.
//

#define MAS_SHORTHAND 
#define MAS_SHORTHAND_GLOBALS

#import "CellOfVideo.h"
#import "Header.h"
#import "ModelOfItemList.h"
#import "ModelOfData.h"
#import "ModelOfCover.h"
@implementation CellOfVideo

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.titleOfLabel = [[UILabel alloc] init];
        self.detilOfLabel = [[UILabel alloc] init];
        self.showImageView = [[UIImageView alloc] init];
        
        [self addSubview:_showImageView];
        [_showImageView addSubview:_titleOfLabel];
        [_showImageView addSubview:_detilOfLabel];
        
        //使图片蒙上一层暗色
        self.contentView.backgroundColor = [UIColor blackColor];
        self.contentView.alpha = 0.4;
        
        
    }
    return self;
}

-(void)layoutSubviews{
    
    [super layoutSubviews];
  
    [self.showImageView makeConstraints:^(MASConstraintMaker *make) {
        //cell的全屏
        make.edges.offset(UIEdgeInsetsMake(0, 0, 0, 0));
        
    }];
    
    [_titleOfLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(_showImageView).with.offset(5);
        make.left.offset(10);
        make.right.offset(-10);
        make.height.offset(40);
        
    }];
    
    [_detilOfLabel makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(_titleOfLabel.bottom).with.offset(5);
        make.left.offset(40);
        make.right.offset(-40);
        make.height.offset(30);
        
    }];
    
    _titleOfLabel.textAlignment = NSTextAlignmentCenter;
    _detilOfLabel.textAlignment = NSTextAlignmentCenter;
    
}

-(void)setModel:(ModelOfItemList *)model{
    
        _model = model ;
    
  [_showImageView sd_setImageWithURL:[NSURL URLWithString:model.modelOfDate.modelOfCover.detail] ];
    
    NSInteger time = [model.modelOfDate.duration  integerValue];
    _titleOfLabel.text = model.modelOfDate.title;
    _titleOfLabel.font = [UIFont systemFontOfSize:23 weight:4];
    _titleOfLabel.textColor = [UIColor whiteColor];
    
    
    NSString *timeString = [NSString stringWithFormat:@"%02ld'%2ld''", time/60, time%60];
    NSString *string = [NSString stringWithFormat:@"#%@ / %@", model.modelOfDate.cate, timeString];
    
    _detilOfLabel.text = string;
    _detilOfLabel.font = [UIFont systemFontOfSize:17];
    _detilOfLabel.textColor = [UIColor whiteColor];
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
